package com.bnz.user.bnzuser.controller;

import com.bnz.common.utils.PhoneFormatCheckUtils;
import com.bnz.pojo.R;
import com.bnz.user.bnzuser.entity.User;
import com.bnz.user.bnzuser.service.UserService;
import com.xxl.sso.core.conf.Conf;
import com.xxl.sso.core.user.XxlSsoUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xy
 * @date 2022/11/29
 */
@Controller
public class UserController {


    @Autowired
    private UserService userService;

    @RequestMapping({"/","/register.html"})
    public String register(HttpServletRequest request){
        //1.1 取得登录用户名
        XxlSsoUser user = (XxlSsoUser) request.getAttribute(Conf.SSO_USER);
        System.out.println("name = " + user.getUsername());
        return "register";
    }

    //2. 获取验证码
    @RequestMapping("user/getCode")
    public R getCode(String phone){
        //2.1 判断手机号是否存在
        if(PhoneFormatCheckUtils.isPhoneLegal(phone)){

        }
        return R.ok();
    }

    @RequestMapping("user/add")

    public R add(@RequestBody User user, String code){
        //3.1 验证输入的验证码与redis中保存的验证码是否是致
//        if(userService.isValidCodeSuccess(user.getPhone(),code)){
//            userService.add(user);
//        }
        return R.ok();
    }

}
